package ipad.asia.controller;


import ipad.asia.entity.Product;
import ipad.asia.service.product.ProductFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class FindByController {
    @Autowired
    private ProductFeign productFeign;

    //分类搜索
    @RequestMapping("/find/kind")
    public String kind(@RequestParam(value = "kind",required = false) String kind,
                       Model model){
        List<Product> byKind = productFeign.findByKind(kind);
        System.out.println("findByKind======="+byKind);
        model.addAttribute("products",byKind);
        return "index";
    }
    //模糊搜索
    @RequestMapping("/find/name")
    public String nameLike(@RequestParam(value = "name",required = false) String name,
                       Model model){
        System.out.println("name====="+name);
        List<Product> byName = productFeign.findByName(name);
        System.out.println("findByName====="+byName);
        model.addAttribute("products",byName);
        return "index";
    }
}
